package mvp.com.bbc.rcjavaretrofitdaggermvp.baseAF;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import butterknife.ButterKnife;
import mvp.com.bbc.rcjavaretrofitdaggermvp.app.utils.EventUtil;

/**
 * Created by 轻吻旧时光 on 2017/4/26.
 */

public abstract class BaseFragment extends Fragment implements View.OnClickListener {

    public View baseView;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(setContentLayout(), container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        this.baseView = view;
        ButterKnife.bind(this, baseView);//注解
        findViews();
        setListeners();
        init();
        EventUtil.register(this);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventUtil.unregister(this);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }

    /***
     * 设置页面布局
     */
    protected abstract int setContentLayout();

    /**
     * 绑定id
     */
    protected abstract void findViews();

    /**
     * 初始化操作
     */
    protected abstract void init();

    /**
     * 事件监听
     */
    protected abstract void setListeners();

    /**
     * EventBus接收器
     *
     * @param action
     */
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEvent(String action) {
//        ToastUtlis.ToastShow_Short(getContext(),action);
    }

}
